home *** CD-ROM | disk | FTP | other *** search
/ Delphi Programmer's Power Pack / Delphi Volume 1.iso / s_to_z / tmmplot / main.pas < prev    next >
Pascal/Delphi Source File  |  1996-09-15  |  11KB  |  381 lines

  1. (*--------------------------------------------------------------------**
  2. **            Fa. MAMAvision Software Consult                             **
  3. **            Wollmatingerstra▀e 70b  D-78467 Konstanz                      **
  4. **          Tel.: (07531)690014     Fax: (07531)690015                  **
  5. **--Projekt-----------------------------------------------------------**
  6. **                          HPGL-Viewer/Printer                           **
  7. **                     SOFTWARE\HPGL\PAS\....                         **
  8. **--Revisionhistory---------------------------------------------------**
  9. **
  10. ■lgb■
  11. ■lge■
  12. **
  13. **--Module------------------------------------------------------------**
  14. **  Modul-Name      : ■modname: HPGLDEMO.pas■
  15. **  Modul-Revision  : ■version: 1.0■
  16. **  Projekt-Revision: ■1.0■
  17. **--------------------------------------------------------------------**
  18. ■nokeywords■
  19. **--------------------------------------------------------------------*)
  20. unit Main;
  21. (*--------------------------------------------------------------------*)
  22. (*                                                                                                  *)
  23. (*     Small Demo Application to demonstrate TMMPlot lite Component                *)
  24. (*                                                                                                  *)
  25. (*--------------------------------------------------------------------*)
  26. interface
  27.  
  28. uses
  29.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  30.   Forms, Dialogs, StdCtrls, Buttons, ExtCtrls, Menus, Gauges, Printers,
  31.   MMplot, Settings;
  32.  
  33. type
  34.   TMainForm = class(TForm)
  35.     MainMenu: TMainMenu;
  36.     FileOpenItem: TMenuItem;
  37.     FilePrintItem: TMenuItem;
  38.     FilePrintSetupItem: TMenuItem;
  39.     FileExitItem: TMenuItem;
  40.     SaveDialog: TSaveDialog;
  41.     PrintDialog: TPrintDialog;
  42.     PrintSetupDialog: TPrinterSetupDialog;
  43.     SpeedBar: TPanel;
  44.     btnopen: TSpeedButton;
  45.     btnhardcopy: TSpeedButton;
  46.     btnprntsetup: TSpeedButton;
  47.     SpeedButton5: TSpeedButton;
  48.     btnPaint: TSpeedButton;
  49.     PaintBox1: TPaintBox;
  50.     Plotinfo: TSpeedButton;
  51.     mInfo: TMenuItem;
  52.     Plotinfo1: TMenuItem;
  53.     mOptions: TMenuItem;
  54.     Anzeige: TMenuItem;
  55.     Toolb: TMenuItem;
  56.     mView: TMenuItem;
  57.     btnprint: TSpeedButton;
  58.     MMPlot1: TMMPlot;
  59.     moIsotropic: TMenuItem;
  60.     moAnisotropic: TMenuItem;
  61.     IsoAniso: TSpeedButton;
  62.     btnsave: TSpeedButton;
  63.     FileSaveItem: TMenuItem;
  64.     moHardCopy: TMenuItem;
  65.     moAbout: TMenuItem;
  66.     OpenDialog: TOpenDialog;
  67.     DragPanel: TPanel;
  68.     Panpad: TPanel;
  69.     btL: TSpeedButton;
  70.     btU: TSpeedButton;
  71.     btD: TSpeedButton;
  72.     btR: TSpeedButton;
  73.     btDL: TSpeedButton;
  74.     btUL: TSpeedButton;
  75.     btUR: TSpeedButton;
  76.     btDR: TSpeedButton;
  77.     btC: TSpeedButton;
  78.     moSettings: TMenuItem;
  79.     btnrot_0: TSpeedButton;
  80.     btnrot_180: TSpeedButton;
  81.     procedure FileOpen(Sender: TObject);
  82.     procedure FilePrint(Sender: TObject);
  83.     procedure FilePrintSetup(Sender: TObject);
  84.     procedure FileExit(Sender: TObject);
  85.     procedure btnPaintClick(Sender: TObject);
  86.     procedure PlotinfoClick(Sender: TObject);
  87.     procedure Plotinfo1Click(Sender: TObject);
  88.     procedure AnzeigeClick(Sender: TObject);
  89.     procedure ToolbClick(Sender: TObject);
  90.     procedure FormCreate(Sender: TObject);
  91.     procedure Filesave(Sender: TObject);
  92.     procedure Hardcopy(Sender: TObject);
  93.     procedure moIsotropicClick(Sender: TObject);
  94.     procedure IsoAnisoClick(Sender: TObject);
  95.     procedure moAboutClick(Sender: TObject);
  96.     procedure PaintBoxMouseDown(Sender: TObject; Button: TMouseButton;
  97.       Shift: TShiftState; X, Y: Integer);
  98.     procedure PaintBoxMouseUp(Sender: TObject; Button: TMouseButton;
  99.       Shift: TShiftState; X, Y: Integer);
  100.     procedure PaintBoxMouseMove(Sender: TObject; Shift: TShiftState; X,
  101.       Y: Integer);
  102.     procedure PanClick(Sender: TObject);
  103.     procedure moSettingsClick(Sender: TObject);
  104.     procedure rotclick(Sender: TObject);
  105.   private
  106.     p1,p2: tpoint;
  107.     r1,r2: trect;
  108.     fcapture : boolean;
  109.   public
  110.     autostretch : boolean;
  111.   end;
  112. var
  113.   MainForm: TMainForm;
  114.  
  115. implementation
  116.  
  117. {$R *.DFM}
  118.  
  119. procedure TMainForm.FileOpen(Sender: TObject);
  120. var activate:boolean;
  121. begin
  122.   if OpenDialog.Execute then
  123.   begin
  124.     Activate := MMPlot1.active;
  125.     MMPlot1.active := false;
  126.     MMPlot1.Close;
  127.     MMPlot1.Filename := OpenDialog.Filename;
  128.     If Activate then MMPlot1.active := true;
  129.   end;
  130. end;
  131.  
  132. procedure TMainForm.FilePrint(Sender: TObject);
  133. var x,y:longint;
  134.     n : word;
  135. begin
  136.   PrintDialog.Options := PrintDialog.Options + [poPagenums];
  137.   PrintDialog.PrintRange := prAllPages;
  138.   if MMPlot1.Size(x,y,n) then n := 1;
  139.   PrintDialog.MinPage := 1;
  140.   PrintDialog.FromPage := 1;
  141.   PrintDialog.MaxPage := n;
  142.   PrintDialog.ToPage := n;
  143.   if PrintDialog.Execute then
  144.   begin
  145.     btnPaint.down := false;
  146.     btnPaint.enabled := false;
  147.     if assigned(MMPlot1) then
  148.       MMPlot1.Close;
  149.     If PrintDialog.PrintRange = prAllPages then
  150.     Begin
  151.       PrintDialog.FromPage := 1;
  152.       PrintDialog.ToPage := 9999;    { ~ n }
  153.     End;
  154. { Procedural Interface to output a plot to a canvas, in this case the printer's }
  155.     OutPlot( OpenDialog.Filename,
  156.              Printer.Canvas,
  157.              Printer,
  158.              2,
  159.              PrintDialog.FromPage,
  160.              PrintDialog.ToPage,
  161.              true);
  162.     btnPaint.enabled := true;
  163.   end;
  164. end;
  165.  
  166. procedure TMainForm.FilePrintSetup(Sender: TObject);
  167. begin
  168.   PrintSetupDialog.Execute;
  169. end;
  170.  
  171. procedure TMainForm.FileExit(Sender: TObject);
  172. begin
  173.   Close;
  174. end;
  175.  
  176. procedure TMainForm.btnPaintClick(Sender: TObject);
  177. begin
  178.   Anzeige.Checked := btnPaint.down;
  179.   MMPlot1.active := btnPaint.down;
  180. end;
  181.  
  182. procedure TMainForm.PlotinfoClick(Sender: TObject);
  183. var s:string;
  184.     x,y:longint;
  185.     n : word;
  186. begin
  187.   if MMPlot1.Size(x,y,n) then Exit;
  188.   s := OpenDialog.Filename + #13#10 +
  189.        'Width: ' + inttostr(x) +
  190.        'mm   Height:' + inttostr(y) + 'mm' + #13#10 +
  191.        'Printpages: ' + inttostr(n);
  192.   MessageDlg(s, mtInformation, [mbOk], 0);
  193. end;
  194.  
  195. procedure TMainForm.Plotinfo1Click(Sender: TObject);
  196. begin
  197.   PlotInfoClick(Sender);
  198. end;
  199.  
  200. procedure TMainForm.AnzeigeClick(Sender: TObject);
  201. begin
  202.   btnPaint.down := not btnPaint.down;
  203.   btnPaintClick(Sender);
  204. end;
  205.  
  206. procedure TMainForm.ToolbClick(Sender: TObject);
  207. begin
  208.   Speedbar.visible := not Toolb.Checked;
  209.   Toolb.Checked := not Toolb.Checked;
  210. end;
  211.  
  212. procedure TMainForm.FormCreate(Sender: TObject);
  213. begin
  214.   fCapture := FALSE;
  215.   IsoAnIso.down := MMPlot1.MapMode = mmAnisotropic;
  216. end;
  217.  
  218. procedure TMainForm.Filesave(Sender: TObject);
  219. var activate:boolean;
  220. begin
  221.   if SaveDialog.Execute then
  222.   begin
  223.     Activate := MMPlot1.active;
  224.     MMPlot1.active := false;
  225.     If MMPlot1.SaveFileAs(SaveDialog.Filename) then
  226.        MessageDlg( 'Store failed !'+#13+
  227.                    'Extension must be .DAT or .TMP'
  228.                   , mtWarning,[mbOk], 0);
  229.     If Activate then MMPlot1.active := true;
  230.   end;
  231. end;
  232.  
  233. procedure TMainForm.Hardcopy(Sender: TObject);
  234. begin
  235.   MMPlot1.Hardcopy;
  236. end;
  237.  
  238. procedure TMainForm.moIsotropicClick(Sender: TObject);
  239. begin
  240.   IsoAnIso.down := Sender = moAnIsotropic;
  241.   IsoAnisoClick(Sender);
  242. end;
  243.  
  244. procedure TMainForm.IsoAnisoClick(Sender: TObject);
  245. begin
  246.   If IsoAnIso.down then
  247.     MMPlot1.MapMode := mmAnisotropic
  248.   Else
  249.     MMPlot1.MapMode := mmIsotropic;
  250.   moIsotropic.Checked := not IsoAnIso.down;
  251.   moAnIsotropic.Checked := IsoAnIso.down;
  252.   MMPlot1.ZoomAll;
  253.   PaintBox1.Refresh;
  254. end;
  255.  
  256. procedure TMainForm.moAboutClick(Sender: TObject);
  257. begin
  258.   MessageDlg( 'Demo for MMPLOT-HPGL/2-Component'+#13+
  259.               'Component: Rev.'+MMPlot1.Version+#13+
  260.               'MMPlot.DLL:Rev.'+MMPLOT.GetDLLVersion+#13+
  261.               'MAMAVISION Software Consult'+#13+
  262.               'CIS 100335,430'
  263.               , mtInformation,[mbOk], 0);
  264. end;
  265.  
  266. procedure TMainForm.PaintBoxMouseDown(Sender: TObject;
  267.   Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  268. begin
  269.   if button = mbLeft then
  270.   begin
  271.     r1.top :=y;
  272.     r1.left:=x;
  273.     r1.bottom := y;
  274.     r1.right := x;
  275.     r2 := r1;
  276.     mainform.ca